﻿using Domain.Interface.Organization;
using Domain.Organization.BusinessObjects;
using Framework.Domain.Interface.SearchCriterias;
using Framework.Domain.Repository;
using Repository.Interface.Organization;
using Repository.Interface.SearchCriterias;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Repository.Organization
{
    public class DepartmentRepository : BoRepository<IDepartmentDomain, DepartmentEntity, DepartmentSearchCriteria>, IDepartmentRepository
    {
        protected override Expression<Func<DepartmentEntity, bool>> ParseSearchCriteria(DepartmentSearchCriteria searchCriteria)
        {
            Expression<Func<DepartmentEntity, bool>> filter = (i => true);

            if (searchCriteria.ParentKeyId.HasValue)
            {
                filter = filter.And(i => i.ParentKeyId == searchCriteria.ParentKeyId.Value);
            }
            if (searchCriteria.Level.HasValue)
            {
                filter = filter.And(i => i.Level == searchCriteria.Level.Value);
            }
            return filter;
        }

        #region IDepartmentRepository 实现

        #region 获取当前部门所有的子部门
        /// <summary>
        /// 获取当前部门所有的子部门
        /// </summary>
        /// <returns></returns>
        public List<IDepartmentDomain> FindCurrentDeptSubDeptList(DepartmentSearchCriteria search)
        {
            return base.GetQuery(search).ToList();
        }
        #endregion

        #endregion

    }
}
